package controller;


import model.Model;
/**
 * this class use as a connection between the view and the model 
 * @author ran & barak
 *
 */
public class CommandsExcuter {
	//all command have a member and he is the one and only instance of this command executer
	private CheckUserExcutor checkUser;
	private NewAccountExcutor newAccount;
	private LogInExcutor log;
	private DbSettingsExcutor dbSettingsExcutor;
	
	//static member for singelton pattern
	private static CommandsExcuter command=new CommandsExcuter();
	/**
	 * @return command member 
	 */
	public static CommandsExcuter getCommand(){
		return command;
	}
	/*
	 * constructor of this class activated only a single time in the program
	 */
	private CommandsExcuter(){
		
		checkUser=new CheckUserExcutor();
		newAccount=new NewAccountExcutor();
		log=new LogInExcutor();
		dbSettingsExcutor = new DbSettingsExcutor();
		
	}
	
	/**
	 * @return DbSettingsExcutor 
	 */
	public DbSettingsExcutor getDbSettingsExcutor(){
		return dbSettingsExcutor;
	}
	/**
	 * @return CheckUserExcutor 
	 */
	public CheckUserExcutor getCheckUser() {
		return checkUser;
	}
	/**
	 * @return NewAccountExcutor 
	 */
	public NewAccountExcutor getNewAccount() {
		return newAccount;
	}
	/**
	 * @return LogInExcutor 
	 */
	public LogInExcutor getLogin() {
		return log;
	}

	
	/**
	 * common interface to all command executors
	 * @author ran & barak
	 *
	 */
	public interface Command {
		/**
		 * the main method of executor class that execute the command 
		 * by activate a certain method in the modal 
		 * all classes that implement this interface must implement this method
		 */
		public void excute() ;

	}

	/**
	 * Inner class that excute the "check if user exist" command 
	 * from the view to the model
	 * @author ran & barak
	 *
	 */
	public class CheckUserExcutor  implements Command {
		//reference to the model
		Model model;
		String userName;
		String Password;
		Boolean returnVal;
		private String email;
		/*
		 * cons` of the executor class
		 */
		private CheckUserExcutor(){
			this.model=Model.getModel();
			
		}
		/**
		 * acutely excute the command
		 */
		public void excute(){
			returnVal=model.checkUser(userName,Password,email);
		}
		/**
		 * set method of the member userName
		 * @param text new value that need to be assign to the member
		 */
		public void setUserName(String text) {
			userName=text;
			
		}
		/**
		 * set method of the member Password
		 * @param text new value that need to be assign to the member
		 */
		public void setPassword(String text) {
			Password=text;
			
		}
		/**
		 * set method of the member Password
		 * @param text new value that need to be assign to the member
		 */
		public void setEmail(String text) {
			email=text;
			
		}
		/**
		 * @return the value of member retVal
		 */
		public Boolean getReturnVal() {
			return returnVal;
			
		}
	
	}
	/**
	 * Inner class that excute the "create new account" command 
	 * from the view to the model
	 * @author ran & barak
	 *
	 */
	public class NewAccountExcutor  implements Command {
		//reference to the model
		Model model;
		String userName;
		String Password;
		Boolean returnVal;
		private String compName;
		private String email;
		private String location;
		private String folderName;
		/*
		 * cons` of the executor class
		 */
		private NewAccountExcutor(){
			this.model=Model.getModel();
			
		}
		/**
		 * acutely excute the command
		 */
		public void excute(){
			returnVal=model.newAccount(userName,Password,email,compName,location,folderName);
		}
		/**
		 * set method of the member userName
		 * @param text new value that need to be assign to the member
		 */
		public void setUserName(String text) {
			userName=text;
			
		}
		/**
		 * set method of the member Password
		 * @param text new value that need to be assign to the member
		 */
		public void setPassword(String text) {
			Password=text;
			
		}
		
		/**
		 * set method of the member compName
		 * @param text new value that need to be assign to the member
		 */
		public void setComputerName(String text) {
			compName=text;
			
		}
		/**
		 * set method of the member email
		 * @param email new value that need to be assign to the member
		 */
		public void setEmail(String email) {
			this.email=email;
			
		}
		/**
		 * set method of the member location
		 * @param text new value that need to be assign to the member
		 */
		public void setLocation(String text) {
			location=text;
			
		}
		/**
		 * set method of the member folderName
		 * @param text new value that need to be assign to the member
		 */
		public void setFolderName(String text) {
			folderName=text;
			
		}
		/**
		 * @return the value of member retVal
		 */
		public Boolean getReturnVal() {
			return returnVal;
			
		}

	}
	/**
	 * Inner class that excute the "log in" command 
	 * from the view to the model
	 * @author ran & barak
	 *
	 */
	public class LogInExcutor  implements Command {
		//reference to the model
		Model model;
		String userName;
		String Password;
		Boolean returnVal;
		/*
		 * cons` of the executor class
		 */
		private LogInExcutor(){
			this.model=Model.getModel();
			
		}
		/**
		 * acutely excute the command
		 */
		public void excute(){
			returnVal=model.login(userName,Password);
		}
		/**
		 * set method of the member userName
		 * @param text new value that need to be assign to the member
		 */
		public void setUserName(String text) {
			userName=text;
			
		}
		/**
		 * set method of the member Password
		 * @param text new value that need to be assign to the member
		 */
		public void setPassword(String text) {
			Password=text;
			
		}
		/** 
		 * @return the value of member retVal
		 */
		public Boolean getReturnVal() {
			return returnVal;
			
		}
		

	}
	/**
	 * Inner class that excute the "db settings" command 
	 * from the view to the model
	 * @author ran & barak
	 *
	 */
	public class DbSettingsExcutor  implements Command {
		//reference to the model
		Model model;
		String dbUserName;
		private String dbPassword;
		
		/*
		 * cons` of the executor class
		 */
		private DbSettingsExcutor(){
			this.model=Model.getModel();
			
		}
		/**
		 * acutely excute the command
		 */
		public void excute(){
			model.setDbSettings(dbUserName,dbPassword);
		}
		/**
		 * set method of the member dbUserName
		 * @param dbUserName new value that need to be assign to the member
		 */
		public void setDbUserName(String dbUserName) {
			this.dbUserName = dbUserName;
		}
		/**
		 * set method of the member dbPassword
		 * @param dbPassword new value that need to be assign to the member
		 */
		public void setDbPassword(String dbPassword) {
			this.dbPassword = dbPassword;
		}
		

	}

}
